package com.blast.cn.bean

import com.blast.cn.R
import com.wxl.common.AppConstant
import com.wxl.common.AppContext
import com.wxl.common.base.BaseEventKeyBean
import com.wxl.common.http.CommonHttpUtil
import com.wxl.common.room.entity.DetonatorEntity
import com.wxl.common.util.DateUtils
import com.wxl.common.util.ObservableUtil
import com.wxl.common.util.SystemUtil

class SettingsItem : BaseEventKeyBean{
    var res:Int
    var text:String
    var action:String
    var timeSurplus:String = ""

    constructor(res: Int, text: String, action: String) {
        this.res = res
        this.text = text
        this.action = action
    }


    companion object {
        fun getSettings():List<SettingsItem>{
            val data = arrayListOf<SettingsItem>()

            data.add(SettingsItem(R.mipmap.icon_me,AppContext.appContext.getLoginName(),""))
            val item = SettingsItem(R.mipmap.icon_surplus_time, "离线登录剩余", "")

            if(AppContext.appContext.checkLoginOutTime()) {
                item.timeSurplus = "已超时"
            } else {
                val loginAccTime = AppContext.appContext.getLoginAccTime()
                val time = System.currentTimeMillis() - loginAccTime - AppConstant.mLoginLimitTime
                item.timeSurplus =  DateUtils.getYMDHMSTime(time)
            }
            data.add(item)

            data.add(SettingsItem(R.mipmap.icon_workbook,"操作手册",""))
            data.add(SettingsItem(R.mipmap.icon_device_info,"设备信息",""))
            data.add(SettingsItem(R.mipmap.icon_software_version,"软件版本",""))
            data.add(SettingsItem(R.mipmap.icon_after_service,"售后服务",""))
            data.add(SettingsItem(R.mipmap.icon_more,"更多",""))
            return data
        }

        /**
         * 获得设备信息
         */
        fun getDeviceInfo(callback:ObservableUtil.Companion.OnNextCallback<List<SettingsItem>>){
            val data = arrayListOf<SettingsItem>()
            CommonHttpUtil.getDetonatorInfo(object : ObservableUtil.Companion.OnNextCallback<DetonatorEntity>(){
                override fun onNext(t: DetonatorEntity) {
                    data.add(SettingsItem(R.mipmap.icon_activation_time,"激活日期",t.time))
                    data.add(SettingsItem(R.mipmap.icon_device_number,"设备编号",t.num))
                    data.add(SettingsItem(R.mipmap.icon_mac_address,"MAC地址", SystemUtil.getMac()))
                    data.add(SettingsItem(R.mipmap.icon_activation_time,"设备型号",t.devicetype))
                    data.add(SettingsItem(R.mipmap.icon_activation_time,"使用单位",t.buydeptid))
                    data.add(SettingsItem(R.mipmap.icon_activation_time,"生成单位",t.deptid))
                    callback.onNext(data)
                }
            })
        }
    }
}